package o;

import android.content.pm.PackageManager.NameNotFoundException;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class erc extends ur {
    private static erc ˋ = null;
    private erd ʽ;
    private rm ˊ;
    private int ˎ;
    private final erf ˏ = new erf();
    private File ॱ;

    public erc(File file, int i) {
        super(file, (long) i);
        this.ॱ = file;
        this.ˎ = i;
        this.ʽ = new erd();
    }

    public static synchronized uj ˋ(File file, int i) {
        uj ujVar;
        synchronized (erc.class) {
            if (ˋ == null) {
                ˋ = new erc(file, i);
            }
            ujVar = ˋ;
        }
        return ujVar;
    }

    private synchronized rm ˊ() throws IOException {
        if (this.ˊ == null) {
            this.ˊ = rm.ॱ(this.ॱ, 1, 1, (long) this.ˎ);
        }
        return this.ˊ;
    }

    public File ˋ(sa saVar) {
        File file = null;
        try {
            c ˎ = ˊ().ˎ(this.ʽ.ˋ(saVar));
            if (ˎ != null) {
                file = ˎ.ˋ(0);
            }
            String ˎ2 = ˎ(saVar);
            if (!(file == null || dof.ˋ(ˎ2))) {
                String path = file.getPath();
                if (path.endsWith("tmp")) {
                    path = path.substring(0, path.indexOf("tmp") - 1);
                }
                eri.ˊ().ˎ(ˎ2, path);
            }
        } catch (IOException e) {
            Logger.ˋ("CacheWrapper", "Unable to get from disk cache");
        }
        return file;
    }

    public void ˊ(sa saVar, uj.c cVar) {
        b ˏ;
        String ˋ = this.ʽ.ˋ(saVar);
        this.ˏ.ॱ(saVar);
        try {
            ˏ = ˊ().ˏ(ˋ);
            if (ˏ != null) {
                File ॱ = ˏ.ॱ(0);
                if (cVar.ˎ(ॱ)) {
                    ˏ.ˎ();
                }
                String ˎ = ˎ(saVar);
                if (!(ॱ == null || dof.ˋ(ˎ))) {
                    ˋ = ॱ.getPath();
                    if (ˋ.endsWith("tmp")) {
                        ˋ = ˋ.substring(0, ˋ.indexOf("tmp") - 1);
                    }
                    eri.ˊ().ˎ(ˎ, ˋ);
                }
                ˏ.ॱ();
            }
            this.ˏ.ˎ(saVar);
        } catch (IOException e) {
            try {
                Logger.ˋ("CacheWrapper", "Unable to put to disk cache");
            } finally {
                this.ˏ.ˎ(saVar);
            }
        } catch (Throwable th) {
            ˏ.ॱ();
        }
    }

    private String ˎ(sa saVar) {
        String obj;
        String str = "";
        try {
            Field declaredField = saVar.getClass().getDeclaredField("sourceKey");
            declaredField.setAccessible(true);
            obj = declaredField.get(saVar).toString();
        } catch (Exception e) {
            Logger.ˋ("CacheWrapper", "Reflection to obtain image url error! icon : " + saVar);
            obj = str;
        }
        try {
            MessageDigest instance;
            if (ˋ() == 1) {
                instance = MessageDigest.getInstance(AaidIdConstant.SIGNATURE_SHA256);
            } else {
                instance = MessageDigest.getInstance("MD5");
            }
            instance.update(obj.getBytes("UTF-8"));
            return doa.ˎ(instance.digest());
        } catch (NoSuchAlgorithmException e2) {
            str = "";
            Logger.ˋ("CacheWrapper", "NoSuchAlgorithmException!");
            return str;
        } catch (UnsupportedEncodingException e3) {
            str = "";
            Logger.ˋ("CacheWrapper", "UnsupportedEncodingException!");
            return str;
        }
    }

    private int ˋ() {
        int i = 0;
        try {
            i = ContentManager.getInstant().getContext().getPackageManager().getApplicationInfo(ContentManager.getInstant().getContext().getPackageName(), DnsConfig.MAX_CACHE_ENTRIES).metaData.getInt("higame_support_function", 0);
        } catch (NameNotFoundException e) {
            Logger.ˏ("CacheWrapper", "CustomDiskLruCacheWrapper isLauncherIconShow PackageName not find");
        }
        return i;
    }
}
